package com.itheima.d17_stringjoiner;

import java.util.StringJoiner;

public class Test {
    public static void main(String[] args) {
//        StringJoiner s = new StringJoiner(",");// 间隔符
        StringJoiner s = new StringJoiner(",", "[", "]");// 间隔符
        s.add("java1");
        s.add("java2");
        s.add("java3");
        System.out.println(s);
        System.out.println(getArrayData(new int[]{1, 23, 4, 5, 6}));
    }

    public static String getArrayData(int[] arr) {
        if (arr == null) return null;
        StringJoiner s = new StringJoiner(",", "[", "]");
        for (int i = 0; i < arr.length; i++) {
            s.add(String.valueOf(arr[i]));
        }
        return s.toString();
    }
}
